package n3273;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static int N,M;
	static int arr[]=new int[100001];
	
	static boolean isok(int m)
	{
		int group=1,sum=0;
		for(int i=0;i<N;i++)
		{
			sum+=arr[i];
			if(sum>m)
			{
				group++;
				sum=arr[i];
			}
		}
		if(group<=M)return true;
		return false;
	}
	
	static int solve(int start,int end)
	{
		while(start<end)
		{
			int mid=(start+end)>>1;
			if(isok(mid))
			{
				end=mid;
			}else {
				start=mid+1;
			}
		}
		return start;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		N=Integer.parseInt(st.nextToken());
		M=Integer.parseInt(st.nextToken());
		int start=0,end=0;
		for(int i=0;i<N;i++)
		{
			arr[i]=Integer.parseInt(bf.readLine());
			if(start<arr[i])start=arr[i];
			end+=arr[i];
		}
		System.out.println(solve(start,end));
	}

}
